$.cookie("GJstype","");
$.cookie("GJhoddy","");
$.cookie("GJjob","");
$.cookie("GJcity","");
$.cookie("GJeducation","");
$.cookie("GJrelation","");
$.cookie("GJcurrent","");

document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                console.log("没有填信息")
            }else{

                location.href="search.html?searchKey="+word;
            }
        }
    }
};
//经验金钱判断能否进入------------------------------------
function moneytest(e){
    //判断能不能去看详情页
    var euserid= e.dataset.euser;
    var thiseid= e.dataset.eid;
    var score=e.dataset.score;
    $.ajax({
        type:"post",
        datatype:"json",
        url:textexpurl,
        data:{"quserId":euserid,"contentId":thiseid,"userId":id,"score":score},
        success:function(d){
            console.log(d);
            if(d.Message=="自己的经验"||d.Message=="已付费"||d.Message=="未付费"){
                $.cookie("paynum",thiseid);
                location.href='shareexppage.html?eid='+thiseid;
            }else{
                $(".moneyinfomob").css("display","block");
            }
        }
    });
}
//去充值
$("#okgobtn").click(function(){
    location.href="scoredetial.html";
});
//取消
$("#cancel").click(function(){
    $(".moneyinfomob").css("display","none");
});
//页面加载进行数据获取
var regs=/(searchKey=)([^\s]+)/;
var sword="";//其他页面传过来的搜索词
if(urlfrom.match(regs)&&urlfrom.match(regs).splice("=")[2]){
    sword=urlfrom.match(regs).splice("=")[2];
    //console.log(sword);
    if(sword.match("%")){sword=decodeURIComponent(sword)}
    $("#lastsearchword").html(sword);
    $("#searchinput").attr('placeholder',sword);
    //发请求调热度列表
    $.ajax({
        type:"get",
        datatype:"json",
        url:hotsearchurl+id+"&searchKey="+sword+"&currentIndex=1&pageSize=10",
        success:function(d){
            console.log(d);
            if(d.Data.length>0){
                $("#pleasewait").css("display","none");
                for(var r=0;r<d.Data.length;r++){
                    d.Data[r].index=r;
                    //新闻
                    if(d.Data[r].contenttype===1){
                        $("#tjplace").append("<li class='Cell'> <a class='tc_inner' href='"+d.Data[r].link+"'> <span class='tc_text'>"+d.Data[r].name+"</span> </a> <div class='tc_stroke'></div> </li>")
                    }
                    //问题
                    if(d.Data[r].contenttype===2){
                        $("#tjplace").append("<li class='Cell'> <a class='tc_inner' href='questiondetail.html?qid="+ d.Data[r].contentId+"'> <span class='tc_text'>"+d.Data[r].name+"</span> <span class='scoreimg rt'><img src='../img/wen01.png'><img src='../img/money04.png'/>"+parseFloat(d.Data[r].score)/100+"</span></a> <div class='tc_stroke'></div> </li>")
                    }
                    //经验
                    if(d.Data[r].contenttype===3){
                        $("#tjplace").append("<li class='Cell'> <a class='tc_inner' onclick='moneytest(this)' data-euser='"+d.Data[r].user.userId+"' data-score='"+d.Data[r].score+"' data-eid='"+d.Data[r].contentId+"'> <span class='tc_text'>"+d.Data[r].name+"</span> <span class='scoreimg rt'><img src='../img/jing01.png'><img src='../img/money04.png'/>"+parseFloat(d.Data[r].score)/100+"</span></a> <div class='tc_stroke'></div> </li>")
                    }
                }
            }else{
                $("#waiting").remove();
                $("#nonews").css("display","block");
            }
        }
    })
}else{
    $("#pleasewait").css("display","none");
}
//当页面返回 搜索键中的内容和input中的内容相同
if($("#searchinput").val()){
    $("#lastsearchword").html($("#searchinput").val());
}
//实时更新按钮中的内容
$("#searchinput").bind("input propertychange",function(){
    $("#lastsearchword").html($("#searchinput").val());
})
//底部点击搜索按钮
var gotosearchbtn=document.getElementById("gotosearch");//底部搜索按钮
var searchword=document.getElementById("searchinput").value;
console.log(searchword);

gotosearchbtn.onclick=function(){
    var searchKey="";
    //如果没有输入内容 有传递的值
    if($("#searchinput").val()===""){
        searchKey=sword;
        console.log("没有内容："+searchKey);
        location.href="searchdetail.html?searchKey="+searchKey;
    }else{ //如果有输入的内容
        if(searchword.match(/^\s+$/g)){ //输入内容为空的判断
            console.log("搜索的内容不能为空");
        }else{
            searchKey=document.getElementById("searchinput").value;
            console.log(searchKey);
            location.href="searchdetail.html?searchKey="+searchKey;
        }
    }
}